<%@page import="com.office.automate.model.employee.EmployeeOverTime"%>
<%@page import="com.office.automate.configuration.property.DatagridPageConfiguration"%>
<%@page import="java.util.List"%>
<%@page import="com.office.automate.frontier.utility.DataConversionUtility"%>
<%@page import="java.util.Calendar"%>
<%@page import="com.office.automate.frontier.utility.ExceptionMessagesManagement"%>
<%@page import="com.office.automate.validation.framework.ValidatorObject"%>
<%@page import="com.office.automate.exception.framework.FrontierVisibleException"%>
<%@page import="java.util.HashMap"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<%@ include file="../common/CommonHeaderInfo.jsp"%>
<title>Employee Leave</title>
</head>
<body>
	<%@ include file="../common/SiteHeaderSection.jsp" %>
	<%@ include file="../common/EmployeeManagementMenu.jsp"%>

		<%
			if (currentUser == null) {
				return;
			}
			Properties configSeqPropspg = ConfigurationProperties.getProps(); 
			Utility utilpg = new Utility(currentUser.getSecurityLevels());
			if (!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("MAIN_EMPLOYEE_MANAGEMENT")) ||  
						!utilpg.isFunctionalSecurityAllow(configSeqPropspg.getProperty("APPLY_FOR_OVERTIME")))  {
				response.sendRedirect("/OfficeAutomation/jsp/HomePage.jsp");
			}
			boolean isValidationErrorExist = false;
			String aDataGridPageID = DatagridPageConfiguration.OVER_TIME_REQUEST;
			String aNextDataRowNumber = (String)request.getAttribute("NextDataRowNumber");
			ExceptionMessagesManagement exceptionMessagesManagement  = null;
			DataConversionUtility dataConversionUtility = new DataConversionUtility();
			int year=Calendar.getInstance().get(Calendar.YEAR);
			long loggedInUserId = 0;
			if (currentUser != null) {
				loggedInUserId= currentUser.getEmployeeId();		
			}
			ValidatorObject validationErrors = (ValidatorObject) request.getAttribute("FieldValidationErrors");
			EmployeeOverTime employeeOverTime = (EmployeeOverTime)request.getAttribute("EmployeeOverTime");
		%>
		<tr>
		<td>
		<form action="/OfficeAutomation/RequestOverTimeServlet" method="post">
		<center>
		<table>
			<tr>
				<td colspan="3"><center><font class="formtablecaption"><u>Make Employee Overtime Request </u></font></center><br /></td>
			</tr>
			<tr>
			<%
			if (validationErrors != null) {
				exceptionMessagesManagement = new ExceptionMessagesManagement(validationErrors.getValidationErrorList());
				isValidationErrorExist = true;
			}
			%>
				  <td>
				  <center>
						<table class="mainContentStyles">
							<tr>
								<td> Over Time Apply Date </td>
								<td>
								  <select name="overtimeday" >
								  	<%
								  		for (int i=1; i<=31; i++) {
									%>
										<option value="<%=i %>" <% if (isValidationErrorExist && i == employeeOverTime.getOvertimeDate().getDate()) { %> selected="selected" <% } %>><%=i %></option>
									<%
								  		}
								  	%>
								 </select>/
								<select name="overtimemonth">
										<%

											for (int i=0; i<12; i++) {
										%>
												<option value="<%=i+1 %>" <% if (isValidationErrorExist && i == employeeOverTime.getOvertimeDate().getMonth()) { %> selected="selected" <% } %>><%=dataConversionUtility.getMonthDescription(i) %></option>
										<%
											}
										%>
	  							  </select>/
	  							  <%=year %>
	  							  	<input type="hidden" name="overtimeyear" value="<%=year %>">
								</td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("OverTimeDate")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("OverTimeDate")  %> </font></td>
								</tr>
							<%
							 }
							%>
							<tr>
							<td> Number Of Hours Worked </td>
							<td> <input type="text" name="numberOfHours" <% if (isValidationErrorExist) { %> value="<%=employeeOverTime.getNumberOfHours() %>" <% } %> size="4"/> </td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("NumberOfHours")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("NumberOfHours")  %> </font></td>
								</tr>
							<%
							 }
							%>
							
							<tr>
								<td>Reason for Overtime</td>
								<td><textarea name="reason" cols="30" rows="5" ><% if (isValidationErrorExist) { %><%=employeeOverTime.getReasonForOverTime() %> <% } %></textarea></td>
							</tr>
							<%
							 if (isValidationErrorExist && exceptionMessagesManagement.checkExistenceOfErrorByKey("Reason")) {
							%>
								<tr>
									<td colspan="2"><font class="errorMessageStyles"> <%=exceptionMessagesManagement.getDetailExceptionMessage("Reason")  %> </font></td>
								</tr>
							<%
							 }
							%>
						</table>
					</center>
					</td>
				</tr>
				<tr>
					<td colspan="3"><div class="formButtonPanel"><input type="submit" name="submit" value="Submit" /></div></td>
				</tr>
			</table>
		  </center>
		</form>
	  </td>
	</tr>
		<tr>
			<td height="20px">
			
			</td>
		</tr>
		<tr>
			<td>
				<center>
				        <jsp:include page="../frameworks/DataGridComponentOverTimeManagement.jsp">
			            	<jsp:param name="aDataGridPageID" value="<%=aDataGridPageID %>" />
			            	<jsp:param name="aNextRowNumber" value="<%=aNextDataRowNumber %>" />
			            	<jsp:param name="aCurrentUser" value="<%=loggedInUserId %>" />
			            	<jsp:param name="aButtonDeleteCaption" value="Cancel" />
			            	<jsp:param name="aButtonsNextPrevious" value="true" />
			        	</jsp:include>
				</center>
			</td>
		</tr>
<%@ include file="../common/SiteFotterSection.jsp" %>
</body>
</html>